/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.commands;

import java.util.Iterator;

import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.helper.ModelerHelper;
import com.cea.papyrus.diagraminterchange2.di2.DiagramElement;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;
import com.cea.papyrus.diagraminterchange2.di2.Property;

/**
 * 
 */
public class OpaqueExpressionBodyDisplayCreateCommand extends StereotypePropertiesDisplayCreateCommand {
	
	/**
	 * 
	 */
	protected Element umlChild;
	
	/**
	 * 
	 * 
	 * @param umlChild 
	 * @param semanticparent 
	 * @param name 
	 * @param parent 
	 */
	public OpaqueExpressionBodyDisplayCreateCommand(String name, DiagramElement semanticparent, DiagramElement parent, Element umlChild) {
		super(name, semanticparent, parent);
		this.umlChild = umlChild;
		setLabel("Display opaque expression body "+name);
	}
	
	
	/**
	 * 
	 * 
	 * @param umlChild 
	 * @param semanticparent 
	 * @param parent 
	 */
	public OpaqueExpressionBodyDisplayCreateCommand(DiagramElement semanticparent, DiagramElement parent, Element umlChild) {
		super(semanticparent, parent);
		this.umlChild = umlChild;
		setLabel("Display opaque expression body "+name);
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.core.common.commands.StereotypePropertiesDisplayCreateCommand#createGraphNode()
	 */
	/**
	 * 
	 * 
	 * @return 
	 */
	protected GraphNode createGraphNode(){
		return factory.createGraphElement(umlChild,null,null,null);
	}

	/**
	 * This method tests if the graphNode is allowed to be created.
	 * 
	 * @return 
	 */
	@Override
	public boolean canExecute() {
		
		Iterator<Property> iterator = semanticParent.getProperty().iterator();
		int count=0;
		while(iterator.hasNext()){
			Property currentProp = iterator.next();
			if(currentProp.getKey().equals(ModelerHelper.OPAQUE_EXPRESSION_BODY_DISPLAY)) {
				count++;
			}
		}
		
		return count==1; 
	}
}
